#include "datamodel.h"

DataModel::DataModel(QObject *parent) :
        QAbstractTableModel(parent), year_time(0)
{
    m_data.push_back(TableRow("Dec", 31));
    m_data.push_back(TableRow("Jan", 31));
    m_data.push_back(TableRow("Feb", 28));
    m_data.push_back(TableRow("Mar", 31));
    m_data.push_back(TableRow("Apr", 30));
    m_data.push_back(TableRow("May", 31));
    m_data.push_back(TableRow("June",30));
    m_data.push_back(TableRow("July",31));
    m_data.push_back(TableRow("Aug", 31));
    m_data.push_back(TableRow("Sep", 30));
    m_data.push_back(TableRow("Oct", 31));
    m_data.push_back(TableRow("Nov", 30));


}


int DataModel::rowCount(const QModelIndex &parent) const
{
    return year_time == 0 ? m_data.size() : 3;
}
int DataModel::columnCount(const QModelIndex &parent) const
{
    return 2;
}

QVariant DataModel::data(const QModelIndex &index, int role) const
{
    if(role == Qt::DisplayRole && index.isValid())
    {
        if(year_time == 0)
        {
            if(index.column() == 0)
                return m_data[index.row()].month;
            else if(index.column() == 1)
                return m_data[index.row()].days;
        }
        else
        {
            if(index.column() == 0)
                return m_data[index.row() + 3*(year_time-1)].month;
            else if(index.column() == 1)
                return m_data[index.row() + 3*(year_time-1)].days;
        }

    }
    return QVariant();
}

void DataModel::filterChanged(int year_time)
{
    this->year_time = year_time;
    this->layoutChanged();

}

